package com.example.log;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Date 2021/7/10
 * @Created by Jonathan
 */
@Aspect
@Slf4j
@Component
public class Logger {

    @Before("@annotation(com.example.log.LogAnnotation)")
    public void beforePrint() {
        log.info("Logger beforePrint run ......");
    }

    /*@After("@annotation(com.example.log.Log)")
    public void afterPrint() {
        log.info("Logger afterPrint run ......");
    }

    @AfterReturning("execution(* com.example.*.*(String)))")
    public void afterReturningPrint() {
        log.info("Logger afterReturningPrint run ......");
    }

    @AfterThrowing("defaultPointcut()")
    public void afterThrowingPrint() {
        log.info("Logger afterThrowingPrint run ......");
    }

    @Around("execution(public * com.linkedbear.spring.aop.b_aspectj.service.FinanceService.addMoney(..))")
    public Object aroundPrint(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("Logger aroundPrint before run ......");
        try {
            Object retVal = joinPoint.proceed();
            log.info("Logger aroundPrint afterReturning run ......");
            return retVal;
        } catch (Throwable e) {
            log.info("Logger aroundPrint afterThrowing run ......");
            throw e;
        } finally {
            log.info("Logger aroundPrint after run ......");
        }
    }

    @Pointcut("execution(* com.linkedbear.spring.aop.b_aspectj.service.*.*(String)))")
    public void defaultPointcut() {

    }*/
}